from typing import List


def permute_with_start(nums: List[int], start: int, res: List[List]):
    if start == len(nums):
        res.append(nums)
    else:
        for i in range(start, len(nums)):
            nums[start], nums[i] = nums[i], nums[start]
            permute_with_start(nums, start + 1, res)
            nums[start], nums[i] = nums[i], nums[start]


def permute(nums: List[int]) -> List[List[int]]:
    res = [[]]
    if len(nums) == 0:
        return res
    else:
        permute_with_start(nums, 0, res)
        return res
